﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for QuangCao
/// </summary>
public class QuangCao
{
    DataConnection data = new DataConnection();
	public QuangCao()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable DLQuangCao()
    {
        string sql = "select * from QuangCao";
        return data.GetData(sql);
    }
    public DataTable TimQC(string ten,string dang,string huy)
    {
        SqlParameter pten=new SqlParameter("@ten",ten);
        SqlParameter pdang=new SqlParameter("@dang",dang);
        SqlParameter phuy=new SqlParameter("@huy",huy);
        string sql = "select * from QuangCao where TenCT like '%'+@ten+'%' or NgayDang=@dang or NgayHuy=@huy ";
        return data.GetData(sql, pten, pdang, phuy);
    }
    public DataTable SuaQC(string ten,string hinh, float gia,int utien,string ul, string dang, string huy)
    {
        SqlParameter pten = new SqlParameter("@ten", ten);
        SqlParameter phinh = new SqlParameter("@hinh", hinh);
        SqlParameter pgia = new SqlParameter("@gia", gia);
        SqlParameter putien = new SqlParameter("@utien", utien);
        SqlParameter pul = new SqlParameter("@url", ul);
        SqlParameter pdang = new SqlParameter("@dang", dang);
        SqlParameter phuy = new SqlParameter("@huy", huy);
        string sql = "update QuangCao set TenCT=@ten,hinhAnh=@hinh,DonGia=@gia,UuTien=@utien,URL=@url,NgayDang=@dang,NgayHuy=@huy";
        return data.GetData(sql, pten,phinh, pgia,putien,pul, pdang, phuy);
    }
    public DataTable ThemQC(string ten,string hinh, float gia,int utien,string ul, string dang, string huy)
    {
        SqlParameter pten = new SqlParameter("@ten", ten);
        SqlParameter phinh = new SqlParameter("@hinh", hinh);
        SqlParameter pgia = new SqlParameter("@gia", gia);
        SqlParameter putien = new SqlParameter("@utien", utien);
        SqlParameter pul = new SqlParameter("@url", ul);
        SqlParameter pdang = new SqlParameter("@dang", dang);
        SqlParameter phuy = new SqlParameter("@huy", huy);
        string sql = "insert into QuangCao values(@ten,@hinh,@gia,@utien,@url,@dang,@huy)";
        return data.GetData(sql, pten,phinh, pgia,putien,pul, pdang, phuy);
    }
    public DataTable XoaQC(string ten)
    {
        SqlParameter pten = new SqlParameter("@ten", ten);
        string sql = "delete from QuangCao where TenCT=@ten";
        return data.GetData(sql, pten);
    }
}
